package com.zzu.securityKeycloak.Repository;

import com.zzu.securityKeycloak.model.Book;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Copyright www.lanhusoft.com
 * Author:Apex Zheng
 * Date:2019/12/11
 * Description:
 */
@Repository
public class BookRepository {
    private static Map<String, Book> books = new ConcurrentHashMap<>();

    static {
        books.put("B01", new Book("B01", "西游记", "吴承恩"));
        books.put("B02", new Book("B02", "红楼梦", "曹雪芹"));
        books.put("B03", new Book("B03", "水浒传", "施耐庵"));
        books.put("B04", new Book("B04", "三国演义", "罗贯中"));
    }

    public List<Book> readAll() {
        List<Book> allBooks = new ArrayList<>(books.values());
        allBooks.sort(Comparator.comparing(Book::getId));
        return allBooks;
    }
}
